import time

import page
from base.base import Base


class PageBackWarehouse(Base):
    # 点击一级标题：仓库
    def page_click_first_level_warehouse(self):
        self.base_click_element(page.back_first_level_warehouse)

    # 点击二级标题：仓库商品管理
    def page_click_second_level_warehouse_management(self):
        self.base_click_element(page.back_second_level_warehouse_management)

    # 切换到仓库商品管理对应的iframe
    def page_switch_warehouse_management_iframe(self):
        self.base_switch_to_iframe(page.back_warehouse_management_iframe)

    # 点击仓库管理页面的“添加”按钮
    def page_click_warehouse_add_btn(self):
        self.base_click_element(page.back_warehouse_add_btn)

    # 点击添加商品弹窗中的商品添加按钮
    def page_click_warehouse_add_product_btn(self):
        self.base_click_element(page.back_warehouse_add_product)
        self.base_click_element(page.back_warehouse_close)

    # 点击目标商品对应的“库存配置”按钮
    def page_click_warehouse_product_stock_btn(self):
        self.base_click_element(page.get_product_warehouse_id()['back_warehouse_add_product_warehouse_btn'])
        time.sleep(1)
        self.base_switch_to_iframe(page.back_warehouse_add_product_warehouse_frame)

    # 输入仓库商品的库存数量
    def page_input_warehouse_product_stock(self, stock_num):
        self.base_in_element_input(page.back_warehouse_add_product_warehouse_row1, stock_num)
        self.base_in_element_input(page.back_warehouse_add_product_warehouse_row2, stock_num)

    # 点击库存配置的“提交”按钮
    def page_submit_warehouse_product_stock(self):
        self.base_click_element(page.back_warehouse_add_product_warehouse_submit)

    # 切换到默认内容（最顶层frame）
    def page_switch_to_default_content(self):
        self.base_switch_to_default_content()

    # 获得截屏
    def page_get_screenshot(self):
        self.base_get_img()

    def page_into_warehouse(self):
        self.page_switch_to_default_content()
        time.sleep(0.5)
        self.page_click_first_level_warehouse()
        time.sleep(0.5)
        self.page_click_second_level_warehouse_management()
        time.sleep(1)
        self.page_switch_warehouse_management_iframe()
        time.sleep(0.5)

    def page_warehouse_add(self):
        self.page_click_warehouse_add_btn()
        time.sleep(0.5)
        self.page_click_warehouse_add_product_btn()
        time.sleep(0.5)

    def page_warehouse(self,product_data):
        self.page_click_warehouse_product_stock_btn()
        time.sleep(0.5)
        self.page_input_warehouse_product_stock(product_data["warehouse_product_stock"])
        time.sleep(0.5)
        self.page_submit_warehouse_product_stock()
        self.page_switch_to_default_content()
        time.sleep(1)
